package cn.wolfcode.wolf2w.strategy.listener;

import cn.wolfcode.wolf2w.strategy.api.domain.Strategy;
import cn.wolfcode.wolf2w.strategy.service.IStrategyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextStartedEvent;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RedisDataInitListener implements ApplicationListener<ContextStartedEvent> {
    @Autowired
    private IStrategyService strategyService;

    @Override
    public void onApplicationEvent(ContextStartedEvent event) {
        System.out.println("-------------------------redis数据初始化-begin-------------------------");
        List<Strategy> list = strategyService.list();
        for (Strategy strategy : list) {
            strategyService.initStrategyHash(strategy.getId());
        }
        System.out.println("--------------------------redis数据初始化-end--------------------------");
    }
}
